package com.yc.bdw.Activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.yc.bdw.Cropimage.ChooseDialog;
import com.yc.bdw.Cropimage.CropHelper;
import com.yc.bdw.PhotoUtils.OSUtils;
import com.yc.bdw.R;
import com.yc.bdw.Widget.RoundImageView;


import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.ui.BindView;

/**
 * Created by Special on 2015/11/18.
 */
public class MyselfActivity extends KJActivity {

    @BindView(id = R.id.iv_user_photo, click = true)
    private RoundImageView iv_user_photo;
    @BindView(id = R.id.iv_history, click = true)
    private ImageView iv_history;
    @BindView(id = R.id.iv_my_comment, click = true)
    private ImageView iv_my_comment;
    @BindView(id = R.id.iv_my_collection, click = true)
    private ImageView iv_my_collection;

    @BindView(id = R.id.iv_waitting_payment, click = true)
    private ImageView iv_waitting_payment;
    @BindView(id = R.id.iv_waitting_shipment, click = true)
    private ImageView iv_waitting_shipment;
    @BindView(id = R.id.iv_waitting_take, click = true)
    private ImageView iv_waitting_take;
    @BindView(id = R.id.iv_finish, click = true)
    private ImageView iv_finish;

    @BindView(id = R.id.rl_store, click = true)
    private RelativeLayout rl_store;
    @BindView(id = R.id.rl_address_manage, click = true)
    private RelativeLayout rl_address_manage;
    @BindView(id = R.id.rl_feedback, click = true)
    private RelativeLayout rl_feedback;
    @BindView(id = R.id.rl_service, click = true)
    private RelativeLayout rl_service;

    @BindView(id=R.id.btn_home,click = true)
    private ImageView  btn_home;
    @BindView(id=R.id.btn_sort,click = true)
    private ImageView  btn_sort;
    @BindView(id=R.id.btn_shoppingcart,click = true)
    private ImageView  btn_shoppingcart;
    @BindView(id=R.id.btn_myself,click = true)
    private ImageView  btn_myself;

    private CropHelper mCropHelper;
    private ChooseDialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_myself);
    }

    @Override
    public void initWidget() {
        super.initWidget();
        Changebackground();
        btn_myself.setBackgroundResource(R.drawable.btn_my_pre);
        mCropHelper = new CropHelper(this, OSUtils.getSdCardDirectory() + "/head.png");
        mDialog = new ChooseDialog(this, mCropHelper);
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            //导航栏
            case R.id.btn_home:
                Changebackground();
                btn_home.setBackgroundResource(R.drawable.btn_home_pre);
                break;
            case R.id.btn_sort:
                Changebackground();
                btn_sort.setBackgroundResource(R.drawable.btn_classify_pre);
                break;
            case R.id.btn_shoppingcart:
                Changebackground();
                btn_shoppingcart.setBackgroundResource(R.drawable.btn_shopping_pre);
                break;
            case R.id.btn_myself:
                Changebackground();
                btn_myself.setBackgroundResource(R.drawable.btn_my_pre);
                break;


            case R.id.iv_user_photo:
                mDialog.popSelectDialog();
                break;
            case R.id.iv_history:
                showActivity(aty, HistoryActivity.class);
                break;
            case R.id.iv_my_comment:
                break;
            case R.id.iv_my_collection:
                showActivity(aty, CollectionActivity.class);
                break;

            case R.id.iv_waitting_payment:
                showActivity(aty, ShipmentActivity.class);
                break;
            case R.id.iv_waitting_shipment:
                showActivity(aty, ShipmentActivity.class);
                break;
            case R.id.iv_waitting_take:
                showActivity(aty, ShipmentActivity.class);
                break;
            case R.id.iv_finish:
                showActivity(aty, ShipmentActivity.class);
                break;

            case R.id.rl_store:
                break;
            case R.id.rl_address_manage:
                showActivity(aty, AddressListActivity.class);
                break;
            case R.id.rl_feedback:
                showActivity(aty, FeedbackActivity.class);
                break;
            case R.id.rl_service:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.e("onActivityResult", requestCode + "**" + resultCode);
        if (requestCode == RESULT_CANCELED) {
            return;
        } else {
            switch (requestCode) {
                case CropHelper.HEAD_FROM_ALBUM:
                    mCropHelper.getDataFromAlbum(data);
                    Log.e("onActivityResult", "接收到图库图片");
                    break;
                case CropHelper.HEAD_FROM_CAMERA:
                    mCropHelper.getDataFromCamera(data);
                    Log.e("onActivityResult", "接收到拍照图片");
                    break;
                case CropHelper.HEAD_SAVE_PHOTO:
                    if (data != null && data.getParcelableExtra("data") != null) {
                        iv_user_photo.setImageBitmap((Bitmap) data.getParcelableExtra("data"));
                        mCropHelper.savePhoto(data, OSUtils.getSdCardDirectory() + "/myHead.png");
                    }
                    break;
                default:
                    Log.e("onActivityResult", "111111");
                    break;
            }
        }
    }

    public void Changebackground(){
        btn_home.setBackgroundResource(R.drawable.btn_home_normal);
        btn_sort.setBackgroundResource(R.drawable.btn_classify_noemal);
        btn_shoppingcart.setBackgroundResource(R.drawable.btn_shopping_normal);
        btn_myself.setBackgroundResource(R.drawable.btn_my_normal);
    }
}
